package cn.itsource.easyexcel.write;

import cn.itsource.constant.Constant;
import cn.itsource.vo.User;
import cn.itsource.util.GenerateUserUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.metadata.WriteSheet;

/**
 * 最简单的写入  方式2
 */
public class WriteDemo2 {
    public static void main(String[] args) {
        String filename = Constant.BATH_URL + "user2.xlsx";
        // 创建ExcelWriter对象
        ExcelWriter excelWriter = EasyExcel.write(filename, User.class).build();
        // 创建Sheet对象
        WriteSheet writeSheet = EasyExcel.writerSheet("用户信息").build();
        try {
            // 向Excel中写入数据
            excelWriter.write(GenerateUserUtil.getUserData(), writeSheet);
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            // 关闭流
            excelWriter.finish();
        }
    }
}

